package com.example.juc.controller;

import java.util.concurrent.atomic.LongAccumulator;
import java.util.concurrent.atomic.LongAdder;

/**
 * @author jl
 * @since 2021/10/10 14:31
 */
public class LongAdderDemo {
    public static void main(String[] args) {
        LongAdder longAdder = new LongAdder();
        longAdder.increment();
        longAdder.increment();
        longAdder.increment();
        System.out.println("longAdder.sum() = " + longAdder.sum());

        LongAccumulator longAccumulator = new LongAccumulator((x, y) -> x - y, 100);
        longAccumulator.accumulate(3);
        longAccumulator.accumulate(5);
        longAccumulator.accumulate(7);
        System.out.println("longAccumulator.longValue() = " + longAccumulator.longValue());
    }
}
